package com.longdaji.decoration.ui.activitiesOfMine.feedback;

import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.widget.TextView;

import com.longdaji.decoration.R;
import com.longdaji.decoration.adapter.MyFragmentPagerAdapter;
import com.longdaji.decoration.base.BaseActivity;

import java.util.ArrayList;
import java.util.List;

import javax.inject.Inject;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class FeedbackActivity extends BaseActivity implements FeedbackContract.IView {

    @Inject
    FeedbackContract.IPresenter mPresenter;
    @Inject
    DoFeedbackFragment doFeedbackFragment;
    @Inject
    SeeFeedbackFragment seeFeedbackFragment;

    @BindView(R.id.tv_tool_title)
    TextView tvTitle;
    @BindView(R.id.view_pager)
    ViewPager viewPager;
    @BindView(R.id.tab_layout)
    TabLayout tabLayout;

    private MyFragmentPagerAdapter myFragmentPagerAdapter;
    private List<Fragment> fragments = new ArrayList<>();


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_feedback);
        setUnBinder(ButterKnife.bind(this));

        if (mPresenter != null)
            mPresenter.setView(this);
        tvTitle.setText("意见反馈");

        initView();
    }

    private void initView() {
        fragments.add(doFeedbackFragment);
        fragments.add(seeFeedbackFragment);
        myFragmentPagerAdapter = new MyFragmentPagerAdapter(getSupportFragmentManager(), fragments, new String[]{"我要反馈", "历史反馈"});
        viewPager.setAdapter(myFragmentPagerAdapter);
        tabLayout.setupWithViewPager(viewPager);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        if (mPresenter != null)
            mPresenter.detachView();
    }


    @OnClick({R.id.rl_tool_back})
    void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.rl_tool_back:
                finish();
                break;
            default:
                break;
        }
    }
}
